package com.dsy.xiangcun_index.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dsy.tools.common.utils.QueryObj;
import com.dsy.tools.entity.TbFood;
import com.dsy.xiangcun_index.service.ITbFoodService;
import com.dsy.xiangcun_index.service.ITbTouService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dsy
 * @since 2021-03-06
 */
@Controller
@RequestMapping("/food")
public class TbFoodController {
    @Autowired
    private ITbFoodService foodService;
    @Autowired
    private ITbTouService stuService;
    /**
     * 分页查看美食推荐列表
     * @param m
     * @param page
     * @param limit
     * @param queryObj
     * @return
     */
    @RequestMapping("/getAllFood")
    public String getAllAround(Model m, @RequestParam(defaultValue = "1") long page, @RequestParam(defaultValue = "10") long limit, QueryObj queryObj, HttpSession session){
        //Mybatis plus强大的条件构造器  Wrapper
        //QueryWrapper ：Entity 对象封装操作类，不是用lambda语法
        QueryWrapper<QueryObj> wrapper = new QueryWrapper<>();

        wrapper.setEntity(queryObj);

        IPage<TbFood> foodPage = foodService.getAllFood(page,limit,wrapper);
        m.addAttribute("foodPage",foodPage);
        m.addAttribute("page",page);
        m.addAttribute("queryObj",queryObj);
        return "/food/food-list";
    }
    /**
     * 根据美食推荐Id查询
     * @param m
     * @param foodId
     * @return
     */
    @RequestMapping("/getFoodById")
    public String getFoodById(Model m,Integer foodId){
        TbFood food=foodService.getFoodById(foodId);
        m.addAttribute("food",food);
        return "/food/food-look";
    }
}

